package com.example.mylibrarybase.yumengmeng06.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mylibrarybase.R;
import com.example.mylibrarybase.bar.initAction_Bar;
import com.example.mylibrarybase.base.baseui.BaseActivity;
import com.example.mylibrarybase.utils.LogUtils;
import com.example.mylibrarybase.yumengmeng03.view.TopTabBar_3;
import com.example.mylibrarybase.yumengmeng06.adapter.MyViewPagerAdapter_06;
import com.example.mylibrarybase.yumengmeng06.fragment.ViewPagerFragment.Fragment_06;
import com.example.mylibrarybase.yumengmeng06.view.yumengmeng06_MyListView_06;
import com.example.mylibrarybase.yumengmeng06.view.yumengmeng06_ViewPager_06;
import com.jingchen.pulltorefresh.PullToRefreshLayout;

import java.util.ArrayList;

public class MainActivity_viewpager_list_06 extends BaseActivity implements TopTabBar_3.CallBack, Fragment_06.CallBack {
    public ArrayList<Fragment> fragments = new ArrayList<>();
    private PullToRefreshLayout ptrl06;
    private yumengmeng06_MyListView_06 mYumengmeng06_myListView;
    private yumengmeng06_ViewPager_06 mYumengmeng06_viewPager;
    private Fragment_06 fragment_1;
    private Fragment_06 fragment_2;
    private Fragment_06 fragment_3;
    private Fragment_06 fragment_4;
    private MyViewPagerAdapter_06 mMyViewPagerAdapter;
    private Fragment_06 fragment_0;
    private TopTabBar_3 mTopTabBar;
    private ArrayList<TextView> mTextViews;
    public int status;
    private initAction_Bar mBase_action_bar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    @Override
    public int getlayouXML() {
       return R.layout.activity_main_activity_viewpager_list_06;
       // return 0;
    }

    @Override
    public void initView() {
        mBase_action_bar = (initAction_Bar) findViewById(R.id.base_action_bar);
        mBase_action_bar
                .setMode(initAction_Bar.AUTO_ONCLICK_MODE)
                .setCallBack(new initAction_Bar.Action_bar_call_back() {
                    @Override
                    public void getAction_barView_backbutton(TextView textView) {
                        textView.setText("返回");
                    }

                    @Override
                    public void getAction_barView_backbutton_icon(ImageView imageView) {

                    }

                    @Override
                    public void getAction_barView_title(TextView textView) {
                        textView.setText("ViewPager+frgment+listView+intcor");
                    }

                    @Override
                    public void getAction_barView_right_icon(ImageView imageView) {

                    }
                });
        mTopTabBar = (TopTabBar_3) findViewById(R.id.TopTabBar);
        mTopTabBar.setCallBack(this);


//        topTabBar.setCallBack(new TopTabBar.CallBack() {
//            @Override
//            public void onClickItemNum(int i) {
//                LogUtils.i("我点的是"+i);
//            }
//        });
//        topTabBar.setCallBack(new TopTabBar.CallBack() {
//            @Override
//            public void onClickItemNum(int i) {
//                LogUtils.i("我点的是"+i);
//            }
//        });
        mTextViews = mTopTabBar.getTextViews();
        for (int i = 0; i < mTextViews.size(); i++) {
            TextView textView = mTextViews.get(i);
            textView.setText("按钮"+i);
        }
//        ptrl06 = ((PullToRefreshLayout) findViewById(R.id.refresh_view06));
//        ptrl06.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {
//            @Override
//            public void onRefresh(final PullToRefreshLayout pullToRefreshLayout) {
//                // 下拉刷新操作
//                new Handler()
//                {
//                    @Override
//                    public void handleMessage(Message msg)
//                    {
//                        // 千万别忘了告诉控件刷新完毕了哦！
//                        pullToRefreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED);
//                    }
//                }.sendEmptyMessageDelayed(0, 5000);
//            }
//
//            @Override
//            public void onLoadMore(final PullToRefreshLayout pullToRefreshLayout) {
//                // 下拉刷新操作
//                new Handler()
//                {
//                    @Override
//                    public void handleMessage(Message msg)
//                    {
//                        // 千万别忘了告诉控件刷新完毕了哦！
//                        pullToRefreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED);
//                    }
//                }.sendEmptyMessageDelayed(0, 5000);
//            }
//        });
//        mYumengmeng06_myListView = (yumengmeng06_MyListView) findViewById(R.id.yumengmeng06_MyListView);


        mYumengmeng06_viewPager = (yumengmeng06_ViewPager_06) findViewById(R.id.yumengmeng06_ViewPager);


       // mYumengmeng06_viewPager.setAdapter();

        initData();
    }

    @Override
    public void initData() {
        fragment_0 = new Fragment_06();
        fragment_1 = new Fragment_06();
        fragment_2 = new Fragment_06();
        fragment_3 = new Fragment_06();
        int uixml = R.layout.fragment_06;
        Bundle bundle1 = new Bundle();
        bundle1.putInt("uixml",uixml);
        bundle1.putInt("status", Fragment_06.fragment_status1);
        fragment_1.setArguments(bundle1);
        Bundle bundle2 = new Bundle();
        bundle2.putInt("uixml",uixml);
        bundle2.putInt("status", Fragment_06.fragment_status2);
        fragment_2.setArguments(bundle2);
        Bundle bundle3 = new Bundle();
        bundle3.putInt("uixml",uixml);
        bundle3.putInt("status", Fragment_06.fragment_status3);
        fragment_3.setArguments(bundle3);
        Bundle bundle0 = new Bundle();
        bundle0.putInt("uixml",uixml);
        bundle0.putInt("status", Fragment_06.fragment_status0);
        fragment_0.setArguments(bundle0);

        fragments.add(fragment_0);
        fragments.add(fragment_1);
        fragments.add(fragment_2);
        fragments.add(fragment_3);

        mMyViewPagerAdapter = new MyViewPagerAdapter_06(getSupportFragmentManager(), fragments);
        mYumengmeng06_viewPager.setAdapter(mMyViewPagerAdapter);

        mYumengmeng06_viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                Fragment_06 item = (Fragment_06)mMyViewPagerAdapter.getItem(position);
                item.setStatus(position);
                LogUtils.i("测试_当前显示ViewPager里面的是"+position+"现在item里面的号是"+item.getStatus());
                TextView textView = mTextViews.get(position);
                mTopTabBar.setTextColors(textView);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


        fragment_0.setCallBack(this);
        fragment_1.setCallBack(this);
        fragment_2.setCallBack(this);
        fragment_3.setCallBack(this);
    }

    @Override
    public void onClickItemNum(int i) {

        status = i;
        LogUtils.i("当前选择的是哪个订单"+status);
        mYumengmeng06_viewPager.setCurrentItem(status);
    }


    @Override
    public void onRefresh(int mStatus) {
       LogUtils.i("测试_下拉刷新"+mStatus);
    }

    @Override
    public void onLoadMore(int mStatus) {
        LogUtils.i("测试_加载更多"+mStatus);
    }
}
